<template>
  <div class="propertyregist pd30 propertyMaintenance maintenancePerson">
    <div class="panelWrap">
      <div class="title flex flexac flexjcsb fs14 cfff fwb pl p-r-20">
        <div>新增维保人员</div>
        <!-- <i class="el-icon-close" @click="handleCloseDialog"></i> -->
      </div>

      <div class="con">
        <!-- <el-button class="defaultbtn saveBtn" @click="handleImport">导入</el-button> -->
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable1 flex flexac">
              <span class="name texttr"><span class="mustval">*</span>姓名：</span>
              <el-input v-model="form.name" class="input" placeholder="请输入机构名称" />
            </div>
          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="inputLable inputLable2 flex flexac">
            <span class="name texttr"><span class="mustval">*</span>性别：</span>
            <div class="flex">
              <el-radio v-model="form.sex" :label="1">男</el-radio>
              <el-radio v-model="form.sex" :label="2">女</el-radio>
            </div>
          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="inputLable inputLable1 flex flexac  ">
            <span class="name texttr"><span class="mustval">*</span>证件类型：</span>
            <!-- <el-input class="input" v-model="form.address" placeholder="请输入使用单位地址"></el-input> -->
            <el-select v-model="form.certType" placeholder="请选择证件类型">
              <el-option v-for="item in certificate" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </div>

        </div>
        <div class="con-row flex flexac pl ">
          <div class="inputLable inputLable2 flex flexac ">
            <span class="name texttr"><span class="mustval">*</span>手机号码：</span>
            <el-input v-model="form.phone" class="input" type="number" placeholder="请输入手机号码" />
          </div>
        </div>

        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">

            <div class="inputLable inputLable2 flex flexac">
              <span class="name texttr"><span class="mustval">*</span>证件号码：</span>
              <el-input v-model="form.certNo" class="input" placeholder="请输入证件号码" />
            </div>

          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable1 flex flexac">
              <span class="name texttr"><span class="mustval">*</span>学历：</span>
              <el-select v-model="form.education" placeholder="请选择学历">
                <el-option v-for="item in education" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </div>
          </div>
        </div>

        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable1 flex flexac">
              <span class="name texttr"><span class="mustval">*</span>电梯安装维修资格证：</span>
              <!-- <el-input class="input" v-model="form.securityPerson" placeholder="请输入安全管理员"></el-input> -->
              <el-select v-model="form.installCertNo" placeholder="请选择电梯安装维修资格证">
                <el-option v-for="item in repair " :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </div>
          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable1 flex flexac">
              <span class="name texttr"><span class="mustval">*</span>是否专业技术人员：</span>
              <div class="flex">
                <el-radio v-model="form.isTechnician" :label="true">是</el-radio>
                <el-radio v-model="form.isTechnician" :label="false">否</el-radio>
              </div>
            </div>
          </div>
        </div>
        <div v-if="form.isTechnician">
          <div class="con-row flex flexac pl ">
            <div class="marginAuto flex flexac">
              <div class="inputLable inputLable1 flex flexac">
                <span class="name texttr"><span class="mustval">*</span>专业类型：</span>
                <el-select v-model="form.majorTypeval" placeholder="请选择专业类型">
                  <el-option v-for="item in majorType" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </div>
            </div>
          </div>
          <div class="con-row flex flexac pl ">
            <div class="marginAuto flex flexac">
              <div class="inputLable inputLable1 flex flexac">
                <span class="name texttr"><span class="mustval">*</span>技术职称：</span>
                <el-select v-model="form.technologytitle" placeholder="请选择技术职称">
                  <el-option v-for="item in technologType" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </div>
            </div>
          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable1 flex flexac">
              <span class="name texttr"><span class="mustval">*</span>是否作业人员：</span>
              <div class="flex">
                <el-radio v-model="form.isWorkman" :label="true">是</el-radio>
                <el-radio v-model="form.isWorkman" :label="false">否</el-radio>
              </div>
            </div>
          </div>
        </div>
        <div v-if="form.isWorkman">

          <div class="con-row flex flexac pl ">
            <div class="marginAuto flex flexac">
              <div class="inputLable inputLable1 flex flexac">
                <span class="name texttr"><span class="mustval">*</span>作业人员职业资格证：</span>
                <el-select v-model="form.zuoyeOccupationval" placeholder="请选择作业人员职业资格证">
                  <el-option v-for="item in workmanProfessionCert" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </div>
            </div>
          </div>

          <div class="con-row flex flexac pl ">
            <div class="marginAuto flex flexac">
              <div class="inputLable inputLable1 flex flexac">
                <span class="name texttr"><span class="mustval">*</span>作业人员技术资格证：</span>
                <el-select v-model="form.zuoyeTechnologyval" placeholder="请选择作业人员技术资格证">
                  <el-option v-for="item in workmanTechniqueCert" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </div>
            </div>
          </div>

        </div>

        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable1 flex flexac">
              <span class="name texttr"><span class="mustval">*</span>参加维保工作日期：</span>
              <el-date-picker v-model="form.joinWorkTime" format="yyyy-MM-dd" value-format="yyyy-MM-dd" type="date" placeholder="选择日期" />
            </div>
          </div>
        </div>
        <div class="con-row flex flexac pl ">
          <div class="marginAuto flex flexac">
            <div class="inputLable inputLable1 flex flexac">
              <span class="name texttr"><span class="mustval">*</span>是否购买保险：</span>
              <div class="flex">
                <el-radio v-model="form.isPurchaseInsurance" :label="true">是</el-radio>
                <el-radio v-model="form.isPurchaseInsurance" :label="false">否</el-radio>
              </div>
            </div>
          </div>
        </div>

        <div class="con-row flex flexac pl ">
          <div class="inputLable wd100 inputLable1 flex ">
            <span class="name texttr"><span class="mustval">*</span>描述：</span>
            <textarea v-model="form.remark" class="markinfo" placeholder="请添加描述信息" />
          </div>
        </div>

      </div>

      <div class="flex  footerBtn m-t-35">
        <el-button v-if="!propertyType" class="m-r-30 btn saveBtn el-icon-circle-check" @click="handleSave(1)">保 存</el-button>
        <el-button v-else type="success" class="m-r-30 btn el-icon-circle-check" @click="handleSave(2)">更 新</el-button>

        <!-- <el-button class="clsoeBtn el-icon-circle-close" @click="handleCloseDialog">关 闭</el-button> -->
      </div>
    </div>

  </div>
</template>

<script>

import { showNotice, checkMobile } from '@/utils/toolclass'
import { staffAdd, maStaffUpdate } from '@/api/maintenance/maintenance'

export default {
  components: {},
  props: {
    isEdit: {
      type: Boolean
    }
  },
  data() {
    return {
      propertyType: false,
      education: [
        {
          value: 0,
          label: '初中'
        }, {
          value: 1,
          label: '中专'
        }, {
          value: 2,
          label: '高中'
        }, {
          value: 3,
          label: '大专'
        }, {
          value: 4,
          label: '本科'
        }, {
          value: 5,
          label: '硕士'
        }, {
          value: 6,
          label: '博士'
        }
      ],
      certificate: [
        {
          value: 1,
          label: '身份证'
        }
      ],
      repair: [
        {
          value: '1',
          label: '电梯修理'
        },
        {
          value: '2',
          label: '维护保养'
        }
      ],
      majorType: [
        {
          value: 0,
          label: 'T1'
        }, {
          value: 1,
          label: 'T2'
        },
        {
          value: 3,
          label: 'T3'
        }, {
          value: 4,
          label: 'A4'
        }
      ],
      technologType: [
        {
          value: 1,
          label: '初级'
        }, {
          value: 2,
          label: '中级'
        },
        {
          value: 3,
          label: '高级'
        }, {
          value: 4,
          label: '技工'
        },
        {
          value: 5,
          label: '高级技工'
        }
      ],
      workmanProfessionCert: [
        {
          value: 1,
          label: '初级'
        }, {
          value: 2,
          label: '中级'
        },
        {
          value: 3,
          label: '高级'
        }, {
          value: 4,
          label: '技工'
        },
        {
          value: 5,
          label: '高级技工'
        }
      ],
      workmanTechniqueCert: [
        {
          value: 0,
          label: '电梯修理'
        }, {
          value: 1,
          label: '电梯修理'
        }
      ],
      form: {
        id: 0,
        name: 'dadaasd',
        sex: 1,
        certType: 1,
        phone: '13602703461',
        certNo: '430426199601097212',
        education: 1,
        installCertNo: '1',
        isTechnician: true,
        isWorkman: false,
        joinWorkTime: '2020-07-08',
        isPurchaseInsurance: true,
        remark: '2132131',
        version: '', //
        skillLevel: '', //
        unitId: '', //
        unitName: '', //
        majorTypeval: 1,
        technologytitle: 1,
        zuoyeOccupationval: 1,
        zuoyeTechnologyval: 1

      }
    }
  },
  created() {
    if (this.$route.query.obj.id !== 0) {
      this.form = this.$route.query.obj
      this.propertyType = true
    }
  },
  mounted() {
    this.$storage.set('upUrl', JSON.stringify({ 'path': '/person' }))
  },
  methods: {
    handleSave(type) {
      if (this.form.name === '') {
        showNotice('error', '提示', '姓名不能为空')
        return
      }
      if (this.form.sex === '') {
        showNotice('error', '提示', '请选择性别')
        return
      }
      if (this.form.phone === '') {
        showNotice('error', '提示', '手机号码不能为空')
        return
      }

      if (!checkMobile(this.form.phone)) {
        showNotice('error', '提示', '手机号码格式不对')
        return
      }

      if (this.form.certNo === '') {
        showNotice('error', '提示', '证件号码不能为空')
        return
      }
      if (this.form.education === '') {
        showNotice('error', '提示', '请选择学历')
        return
      }
      if (this.form.installCertNo === '') {
        showNotice('error', '提示', '请选择电梯安装维修资格证')
        return
      }
      if (!this.form.isTechnician && !this.form.isWorkman) {
        showNotice('error', '提示', '专业技术人员和作业人员选项必须有一项为选中')
        return
      }

      if (this.form.joinWorkTime === '') {
        showNotice('error', '提示', '请选择参加维保工作日期')
        return
      }

      if (this.form.remark === '') {
        showNotice('error', '提示', '描述不能为空')
        return
      }

      const params = {

        certNo: this.form.certNo, // 证件号码
        certType: this.form.certType, // 证件类型
        duties: this.form.duties, // 职务
        education: this.form.education, // 学历
        id: this.form.id, // id
        installCertNo: this.form.installCertNo, // 安装维修资格证号
        isPurchaseInsurance: this.form.isPurchaseInsurance, // 是否购买保险
        isTechnician: this.form.isTechnician, // 是否专业技术人员
        isWorkman: this.form.isWorkman, // 是否作业人员
        joinWorkTime: this.form.joinWorkTime, // 参加维保工作时间
        majorType: this.form.majorTypeval, // 专业类型
        name: this.form.name, // 姓名
        phone: this.form.phone, // 联系电话
        remark: this.form.remark, // 备注
        sex: this.form.sex, // 性别
        skillLevel: this.form.skillLevel, // 技术等级 ----
        technologytitle: this.form.technologytitle, // 技术职称
        // unitId: this.form.unitId, // 维保单位ID -----
        // unitName: this.form.unitName, // 维保单位名称 ------
        version: this.form.version, // 版本号 -------
        workmanProfessionCert: this.form.zuoyeOccupationval, // 作业人员职业资格证
        workmanTechniqueCert: this.form.zuoyeTechnologyval // 作业人员技术资格证
      }
      if (type === 1) {
        this.handlePropertyAdd(params)
      } else if (type === 2) {
        this.handleModify(params)
      }
      this.$router.push({ path: '/personQuery' })
    },
    handleModify(obj) {
      maStaffUpdate(obj).then((res) => {
        if (res.code === '000000') {
          showNotice('success', '提示', '修改成功!')
          this.$emit('handleRefresh')
          this.$emit('handleCloseDialog')
        } else {
          // showNotice('error', '提示', res.msg)
        }
      })
    },
    handleCloseDialog() {
      this.$emit('handleCloseDialog')
      this.$emit('handleRefresh')
    },
    handlePropertyAdd(obj) {
      staffAdd(obj).then((res) => {
        if (res.code === '000000') {
          showNotice('success', '提示', '保存成功!')
          this.$emit('handleRefresh')
          this.$emit('handleCloseDialog')
        } else {
          // showNotice('error', '提示', res.msg)
        }
      })
    }
  }
}
</script>

<style rel='stylesheet/scss' lang='scss' scoped>
@import "@/styles/addtable.scss";
.el-icon-circle-check:before {
  margin-right: 4px;
}
.con {
  padding-left: 50px;
  margin-top: 30px;
  .con-row {
    padding: 15px 0px;
  }
  .inputLable .input {
    height: 36px;
  }
}
.btn {
  width: 100px;
  height: 40px;
}
.inputLable input {
  width: 450px;
}
.inputLable .name {
  width: 190px !important;
  padding-right: 20px;
}
</style>
